package com.landeb.shop.huo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.landeb.shop.R;
import com.landeb.shop.huo.bean.BeanActShopsCollectionLV;

import java.util.List;

/**
 * Created by blade on 2016/11/12.
 */

public class ActShopsCollectionLVAdapter extends BaseAdapter {

    private Context mContext;
    private LayoutInflater mInflater;
    private List<BeanActShopsCollectionLV.DataBean.ListBean> mList;

    public ActShopsCollectionLVAdapter(Context context, List<BeanActShopsCollectionLV.DataBean.ListBean> list) {
        mContext = context;
        mList = list;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {

        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            view = mInflater.inflate(R.layout.item_act_shops_collection_lv, viewGroup, false);

            holder = new ViewHolder();

            holder.mTitle = (TextView) view.findViewById(R.id.tv_title_item_act_shops_collection_lv);
            holder.mFavouriteCount = (TextView) view.findViewById(R.id.tv_favourite_item_act_shops_collection_lv);
            holder.mLogo = (ImageView) view.findViewById(R.id.iv_item_act_shops_collection_lv);

            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        String title = mList.get(i).getName();
        holder.mTitle.setText(title);
        holder.mFavouriteCount.setText("共有" + mList.get(i).getFavorite() + "人关注");
        Glide.with(mContext)
                .load(mList.get(i).getLogo())
                .placeholder(R.drawable.loading_pic)
                .error(R.drawable.error_pic)
                .into(holder.mLogo);


        return view;
    }

    private class ViewHolder {
        private TextView mTitle; //文字
        private TextView mFavouriteCount;
        private ImageView mLogo;
    }
}
